<template>
  <div>
    <el-dialog
      width="90%"
      title="Single Set Of Equipment Battery Swap Records"
      :visible.sync="show"
      :destroy-on-close="true"
      @close="closeFn"
      :append-to-body="true"
    >
      <r-table
        :isPagination="true"
        :isHandle="true"
        :tableData="tableData"
        :tableCols="tableCols"
        :tablePage="pagination"
        :loading="tableLoading"
        :tableHandles="tableHandles"
        :isSelection="false"
      />
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "Abnormal",
  data() {
    return {
      show: false,
      row: {},
      tableLoading: false,
      tableData: [],
      tableHandles: [],
      pagination: { limit: 10, offset: 1, total: 1 },

      tableCols: [
        {
          label: "Device Number",
          prop: "deviceNo"
        },
        {
          label: "Username",
          prop: "userName"
        },
        {
          label: " User Type",
          prop: "userType",
          formatter: e =>
            e.userType == 1
              ? "WeChat"
              : e.userType == 2
              ? "Alipay"
              : e.userType == 3
              ? "Maintenance"
              : "--"
        },
        {
          label: "Phone码",
          prop: "phone"
        },
        {
          label: "Collect Battery",
          prop: "cabinetNo",
          formatter: e =>
            e.cabinetNo ? e.cabinetNo + "号柜门领取Battery" : "--"
        },
        {
          label: "Collect BatteryStatus",
          prop: "statusStr",
          itemClass: e =>
            e.statusStr == "仓门打开Failure" || e.statusStr == "未领取Battery"
              ? "danger"
              : e.statusStr == "Success"
              ? "success"
              : "",
          formatter: e => (e.statusStr ? e.statusStr : "--")
        },
        {
          label: "Collect BatteryBattery",
          prop: "batteryNo",
          formatter: e => (e.batteryNo ? e.batteryNo : "--")
        },
        {
          label: "Return Battery",
          prop: "returnCabinetNo",
          formatter: e =>
            e.returnCabinetNo ? e.returnCabinetNo + "号柜门ReturnBattery" : "--"
        },
        {
          label: "Return BatteryStatus",
          prop: "returnStatusStr",
          itemClass: e =>
            e.returnStatusStr == "仓门打开Failure" ||
            e.returnStatusStr == "Not ReturnedBattery"
              ? "danger"
              : e.returnStatusStr == "Success"
              ? "success"
              : "",
          formatter: e => (e.returnStatusStr ? e.returnStatusStr : "--")
        },
        {
          label: "Return BatteryBattery",
          prop: "returnBatteryNo",
          formatter: e => (e.returnBatteryNo ? e.returnBatteryNo : "--")
        },
        {
          label: "Business Type",
          prop: "oprType",
          formatter: e =>
            e.oprType == 0
              ? "管理员开门"
              : e.oprType == 1
              ? "租Battery"
              : e.oprType == 2
              ? "Battery Swap"
              : e.oprType == 3
              ? "寄存Battery"
              : e.oprType == 4
              ? "Deposit退Return Battery池"
              : "--"
        },
        // {
        //   label: '开门Status',
        //   prop: 'result',
        //   itemClass: e => (e.result == 0 ? 'danger' : e.result == 1 ? 'success' : ''),
        //   formatter: e => (e.result == 0 ? 'Failure' : e.result == 1 ? 'Success' : '--')
        // },
        // {
        //   label: 'BatteryStatus',
        //   prop: 'isBattery',
        //   formatter: e => (e.oprType == 1 && e.isBattery == 0 ? '未领取' : e.oprType == 1 && e.isBattery == 1 ? '已领取' : e.oprType == 2 && e.isReturn == 0 ? 'Not Returned' : e.oprType == 2 && e.isReturn == 1 ? '已Return' : e.oprType == 3 && e.isReturn == 0 ? 'Not Returned' : e.oprType == 3 && e.isReturn == 1 ? '已Return' : e.oprType == 4 && e.isReturn == 0 ? 'Not Returned' : e.oprType == 4 && e.isReturn == 1 ? '已Return' : e.oprType == 0 && e.isBattery == 0 ? '未领取' : e.oprType == 0 && e.isBattery == 1 ? '已领取' : '--'),
        //   itemClass: e => (e.oprType == 2 && e.isReturn == 0 ? 'danger' : e.oprType == 3 && e.isReturn == 0 ? 'danger' : e.oprType == 4 && e.isReturn == 0 ? 'danger' : ''),
        // },
        {
          label: "Order Number",
          prop: "orderNo"
        },
        {
          label: "Operation Time",
          prop: "ctime"
        }
        // { label: "Completion Time", prop: "ftime", },
      ]
    };
  },
  watch: {
    "pagination.offset": {
      handler(newValue) {
        if (newValue) {
          this.getData();
        }
      },
      deep: true // 深度监听
    },
    "pagination.limit": {
      handler(newValue) {
        if (newValue) {
          this.getData();
        }
      },
      deep: true // 深度监听
    }
  },
  created() {
    this.show = false;
  },
  mounted() {},
  methods: {
    closeFn() {
      this.show = false;
      console.log(222555);
    },
    async getData(num, size) {
      let parm = {
        deviceType: "",
        deviceNo: this.row.deviceNo,
        oprType: "",
        result: "",
        phone: "",
        orderNo: "",
        pageNum: num || this.pagination.offset,
        pageSize: size || this.pagination.limit
      };
      let res = await this.apis.deviceLog_list(parm);

      const list = res.rows || [];
      this.tableData = list;
      this.pagination.total = res.total;
    },
    del(row) {
      this.$confirm("Confirm要Delete吗?", "Hint", {
        confirmButtonText: "Confirm",
        cancelButtonText: "Cancel",
        type: "warning"
      })
        .then(async () => {
          const res = await this.apis.alarm_del({
            id: row.id
          });

          this.$message({
            type: "success",
            message: "DeleteSuccess!"
          });
        })
        .catch(() => {});
    },
    show_fun(row) {
      console.log(222, row);
      this.row = row;
      this.show = true;

      this.getData();
    }
  }
};
</script>

<style scoped lang="scss"></style>
